<?php
namespace Qgs\Model;
use Qgs\Model\BaseModel;
use \Think\Db;
use Think\Model;


class StarbuyFlashsalesModel extends Model  {
    // 默认 会员ID
    public $member_id = 714;

    /**
     * @param $id
     * 闪购
     */
    public function getList($id){
        $f_goods = M('starbuy_flashsales_goods');
        $ruleInfo = $this->where(['special_id'=> $id])->find();
        $data = M('starbuy_flashsales_time')->where(['special_id'=> $id])->order('end_time ASC')->select();
        $lengh = count($data);
        foreach($data as $k1 => &$v1){
            $v1['begin_time'] = date('Y-m-d H:i:s',$v1['begin_time']);
            $v1['end_time'] = date('Y-m-d H:i:s',$v1['end_time']);
            //状态（即将开始、已结束）
            $time = time();
            /* echo '<pre>';
             var_dump($v1['begin_time']);
             var_dump($time);
             var_dump($v1['end_time']);*/
            if($v1['begin_time'] < $time && $time< $v1['end_time']){
                // echo 1;
                $data[$k1]['stat'] = '进行中';
                $data[$k1]['p'] = 0;
            }else if($time < $v1['begin_time']){
                //echo 2;
                $data[$k1]['stat'] = '即将开始';
                $data[$k1]['p'] = 1;
            }else{
                //echo 3;
                $data[$k1]['stat'] = '已结束';
                $data[$k1]['p'] = 0;
            }
            //查询货品
            $g_data = $f_goods->alias('sfg')->field('sfg.*,sp.p_name,sp.price,sp.store')
                ->join(C('DB_PREFIX').'b2c_store_product sp on sp.store_pid = sfg.store_pid', 'LEFT')
                ->where( array('tid'=> $v1['tid']))->select();
            $vg_data = array();
            $p_data = array();
           /* foreach($g_data as $k2 => $v2){
                $vg_data[] = $v2['store_pid'];
                $p_data[$v2['products_id']] = array('newprice'=>$v2['promotion_price'],'initnum'=>$v2['initnum']);
            }*/
            //$data[$k1]['store_pids'] = $vg_data;
            $data[$k1]['products'] = $g_data;
        }
        $ruleInfo['dt_info'] = $data;
        return $ruleInfo;
    }




}